
clear all 

//define folder global here

gl Inputs "$folder\1_Inputs"
gl Intermediate "$folder\2_Intermediate"
gl Outputs "$folder\3_Outputs"

********************************************************************************
********************************************************************************
**# TABLE H.1

use "${Intermediate}\Combined for forloops.dta", clear

keep if inlist(item, "co", "se", "obs")
keep if inlist(outcome, "earn", "empl", "home", "eshu", "move")
keep if inlist(time, "q0104", "q0508")
keep if inlist(spec, "ivac")
drop if group=="gr0" | group=="gr1" | group=="a"

gen 	comparison = "gender" 	if group=="m" | group=="f"
replace comparison = "race" 	if group=="b" | group=="n"

gen 	base = "_base" 		if group=="f" | group=="b"
replace base = "_notbase" 	if group=="m" | group=="n" 

drop group

 
* T-TESTS

replace value = subinstr(value, "(", "", .)	
replace value = subinstr(value, ")", "", .)	
replace value = subinstr(value, ",", "", .)	
replace value = subinstr(value, "*", "", .)	
destring(value), replace 

reshape wide value, i(outcome spec time geo base comparison) j(item) string 
reshape wide valueco valuese valueobs, i(outcome spec time geo comparison) j(base) string 

rename value* *
rename *_base base_*
rename *_notbase notbase_*

// create standard deviation variable for ttesti command
gen base_sd = base_se * sqrt(base_obs)
gen notbase_sd = notbase_se * sqrt(notbase_obs)

order base_obs base_co base_sd notbase_obs notbase_co notbase_sd
gen pvalue_sd = .
gen pvalue_se = .

forval i=1(1)60 {
	
	di `i'
	
	levelsof base_obs in `i', 	clean local(b_obs)
	levelsof base_co in `i', 	clean local(b_co)
	levelsof base_sd in `i', 	clean local(b_sd)
	
	levelsof notbase_obs in `i', 	clean local(nb_obs)
	levelsof notbase_co in `i', 	clean local(nb_co)
	levelsof notbase_sd in `i', 	clean local(nb_sd)
	
	levelsof base_se in `i', 	clean local(b_se)
	levelsof notbase_se in `i', clean local(nb_se)
	
	ttesti `b_obs' `b_co' `b_sd' `nb_obs' `nb_co' `nb_sd'
	replace pvalue_sd = r(p) in `i'
	
	ttesti `b_obs' `b_co' `b_se' `nb_obs' `nb_co' `nb_se' // i think this is wrong
	replace pvalue_se = r(p) in `i'
	
	
}

keep outcome spec time geo comparison pvalue_sd 
gen value = string(pvalue, "%10.3fc")
drop pvalue

gen 	group = "g" if comparison=="gender"
replace group = "r" if comparison=="race"
drop comparison 

gen 	item = "pv"

order outcome group spec time geo item value 

* ADD BACK THE FULL DATA

append using "${Intermediate}\Combined for forloops.dta"

keep if inlist(outcome, "earn", "empl", "home", "eshu", "move")
keep if inlist(time, "q0104", "q0508")
keep if inlist(spec, "ivac")
drop if group=="gr0" | group=="gr1" | group=="a"

levelsof outcome, local(outcomes)
levelsof group, local(groups)
levelsof spec, local(specs)
levelsof time, local(times)
levelsof geo, local(geos)
levelsof item, local(items)

foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach grox in `groups' {
		local id2 = "`grox'"
		
		foreach spex in `specs' {
			local id3 = "`spex'"
			
			foreach timx in `times' {
				local id4 = "`timx'"
				
				foreach geox in `geos' {
					local id5 = "`geox'"
					
					foreach itex in `items' {
						local id6 = "`itex'"
		
					levelsof value if 	outcome=="`outx'" & ///
										group=="`grox'" & ///
										spec=="`spex'" & ///
										time=="`timx'" & ///
										geo=="`geox'" & ///
										item=="`itex'" , ///
						clean local(`id1'_`id2'_`id3'_`id4'_`id5'_`id6')
						di "`id1'_`id2'_`id3'_`id4'_`id5'_`id6'"
						
					}
				}
			}
		}
	}
}

				
gl x " "

texdoc init "${Outputs}/Supplementary data_Table_H1.tex", replace force 
tex {\footnotesize \begin{tabular}{l c c c c c c c} \hline \toprule ///
	& \multicolumn{3}{c}{\textbf{1-4 Quarters After Filing}} ///
	& & \multicolumn{3}{c}{\textbf{5-8 Quarters After Filing}} \\

tex \cmidrule{2-4} \cmidrule{6-8}	
	
tex  & Female	& Male 	& p-value	& & Female 	& Male 	& p-value \\
tex & (1) 		& (2) 	& (3)		& & (4) 	& (5) 	& (6) \\

tex \cmidrule{2-4} \cmidrule{6-8}

tex \multicolumn{8}{l}{\textbf{\underline{By Gender}}} \\

tex $x ~~~Earnings: 	& `earn_f_ivac_q0104_b_co' 		& `earn_m_ivac_q0104_b_co' 		& `earn_g_ivac_q0104_b_pv' & ///
							& `earn_f_ivac_q0508_b_co' 		& `earn_m_ivac_q0508_b_co' 		& `earn_g_ivac_q0508_b_pv' \\	
tex							& `earn_f_ivac_q0104_b_se' 		& `earn_m_ivac_q0104_b_se' 		& & ///
							& `earn_f_ivac_q0508_b_se' 		& `earn_m_ivac_q0508_b_se' 		& \\							
tex  				 		& [`earn_f_ivac_q0104_b_obs']   & [`earn_m_ivac_q0104_b_obs']	& &	///
							& [`earn_f_ivac_q0508_b_obs']   & [`earn_m_ivac_q0508_b_obs']	& \\

tex \multicolumn{8}{l}{ } \\
tex $x ~~~Employment: 	& `empl_f_ivac_q0104_b_co' 		& `empl_m_ivac_q0104_b_co' 		& `empl_g_ivac_q0104_b_pv' & ///
							& `empl_f_ivac_q0508_b_co' 		& `empl_m_ivac_q0508_b_co' 		& `empl_g_ivac_q0508_b_pv' \\	
tex							& `empl_f_ivac_q0104_b_se' 		& `empl_m_ivac_q0104_b_se' 		& & ///
							& `empl_f_ivac_q0508_b_se' 		& `empl_m_ivac_q0508_b_se' 		& \\							
tex  				 		& [`empl_f_ivac_q0104_b_obs']   & [`empl_m_ivac_q0104_b_obs']	& &	///
							& [`empl_f_ivac_q0508_b_obs']   & [`empl_m_ivac_q0508_b_obs']	& \\
							
tex \multicolumn{8}{l}{ } \\
tex $x ~~~Not at eviction address: 	& `move_f_ivac_q0104_b_co' 		& `move_m_ivac_q0104_b_co' 		& `move_g_ivac_q0104_b_pv' & ///
							& `move_f_ivac_q0508_b_co' 		& `move_m_ivac_q0508_b_co' 		& `move_g_ivac_q0508_b_pv' \\	
tex							& `move_f_ivac_q0104_b_se' 		& `move_m_ivac_q0104_b_se' 		& & ///
							& `move_f_ivac_q0508_b_se' 		& `move_m_ivac_q0508_b_se' 		& \\							
tex  				 		& [`move_f_ivac_q0104_b_obs']   & [`move_m_ivac_q0104_b_obs']	& &	///
							& [`move_f_ivac_q0508_b_obs']   & [`move_m_ivac_q0508_b_obs']	& \\

tex \multicolumn{8}{l}{ } \\							
tex $x ~~~Emergency shelter: 	& `eshu_f_ivac_q0104_b_co' 		& `eshu_m_ivac_q0104_b_co' 		& `eshu_g_ivac_q0104_b_pv' & ///
							& `eshu_f_ivac_q0508_b_co' 		& `eshu_m_ivac_q0508_b_co' 		& `eshu_g_ivac_q0508_b_pv' \\	
tex							& `eshu_f_ivac_q0104_b_se' 		& `eshu_m_ivac_q0104_b_se' 		& & ///
							& `eshu_f_ivac_q0508_b_se' 		& `eshu_m_ivac_q0508_b_se' 		& \\							
tex  				 		& [`eshu_f_ivac_q0104_b_obs']   & [`eshu_m_ivac_q0104_b_obs']	& &	///
							& [`eshu_f_ivac_q0508_b_obs']   & [`eshu_m_ivac_q0508_b_obs']	& \\
							
tex \multicolumn{8}{l}{ } \\							
tex $x ~~~Any homelessness services: 	& `home_f_ivac_q0104_b_co' 		& `home_m_ivac_q0104_b_co' 		& `home_g_ivac_q0104_b_pv' & ///
							& `home_f_ivac_q0508_b_co' 		& `home_m_ivac_q0508_b_co' 		& `home_g_ivac_q0508_b_pv' \\	
tex							& `home_f_ivac_q0104_b_se' 		& `home_m_ivac_q0104_b_se' 		& & ///
							& `home_f_ivac_q0508_b_se' 		& `home_m_ivac_q0508_b_se' 		& \\							
tex  				 		& [`home_f_ivac_q0104_b_obs']   & [`home_m_ivac_q0104_b_obs']	& &	///
							& [`home_f_ivac_q0508_b_obs']   & [`home_m_ivac_q0508_b_obs']	& \\
							
tex \midrule					
tex  & Black	& Not Black 	& p-value	& & Black 	& Not Black & p-value \\
tex  & (1) 	& (2) 			& (3)		& & (4) 	& (5) 		& (6) \\

tex \cmidrule{2-4} \cmidrule{6-8}

tex \multicolumn{8}{l}{\textbf{\underline{By Race}}} \\
tex $x ~~~Earnings: 		& `earn_b_ivac_q0104_b_co' 		& `earn_n_ivac_q0104_b_co' 		& `earn_r_ivac_q0104_b_pv' & ///
							& `earn_b_ivac_q0508_b_co' 		& `earn_n_ivac_q0508_b_co' 		& `earn_r_ivac_q0508_b_pv' \\	
tex							& `earn_b_ivac_q0104_b_se' 		& `earn_n_ivac_q0104_b_se' 		& & ///
							& `earn_b_ivac_q0508_b_se' 		& `earn_n_ivac_q0508_b_se' 		& \\							
tex  				 		& [`earn_b_ivac_q0104_b_obs']   & [`earn_n_ivac_q0104_b_obs']	& &	///
							& [`earn_b_ivac_q0508_b_obs']   & [`earn_n_ivac_q0508_b_obs']	& \\
							
tex \multicolumn{8}{l}{ } \\
tex $x ~~~Employment:		& `empl_b_ivac_q0104_b_co' 		& `empl_n_ivac_q0104_b_co' 		& `empl_r_ivac_q0104_b_pv' & ///
							& `empl_b_ivac_q0508_b_co' 		& `empl_n_ivac_q0508_b_co' 		& `empl_r_ivac_q0508_b_pv' \\	
tex							& `empl_b_ivac_q0104_b_se' 		& `empl_n_ivac_q0104_b_se' 		& & ///
							& `empl_b_ivac_q0508_b_se' 		& `empl_n_ivac_q0508_b_se' 		& \\							
tex  				 		& [`empl_b_ivac_q0104_b_obs']   & [`empl_n_ivac_q0104_b_obs']	& &	///
							& [`empl_b_ivac_q0508_b_obs']   & [`empl_n_ivac_q0508_b_obs']	& \\
				
tex \multicolumn{8}{l}{ } \\				
tex $x ~~~Not at eviction address:	& `move_b_ivac_q0104_b_co' 		& `move_n_ivac_q0104_b_co' 		& `move_r_ivac_q0104_b_pv' & ///
							& `move_b_ivac_q0508_b_co' 		& `move_n_ivac_q0508_b_co' 		& `move_r_ivac_q0508_b_pv' \\	
tex							& `move_b_ivac_q0104_b_se' 		& `move_n_ivac_q0104_b_se' 		& & ///
							& `move_b_ivac_q0508_b_se' 		& `move_n_ivac_q0508_b_se' 		& \\							
tex  				 		& [`move_b_ivac_q0104_b_obs']   & [`move_n_ivac_q0104_b_obs']	& &	///
							& [`move_b_ivac_q0508_b_obs']   & [`move_n_ivac_q0508_b_obs']	& \\
	
tex \multicolumn{8}{l}{ } \\	
tex $x ~~~Emergency shelter: 	& `eshu_b_ivac_q0104_b_co' 		& `eshu_n_ivac_q0104_b_co' 		& `eshu_r_ivac_q0104_b_pv' & ///
							& `eshu_b_ivac_q0508_b_co' 		& `eshu_n_ivac_q0508_b_co' 		& `eshu_r_ivac_q0508_b_pv' \\	
tex							& `eshu_b_ivac_q0104_b_se' 		& `eshu_n_ivac_q0104_b_se' 		& & ///
							& `eshu_b_ivac_q0508_b_se' 		& `eshu_n_ivac_q0508_b_se' 		& \\							
tex  				 		& [`eshu_b_ivac_q0104_b_obs']   & [`eshu_n_ivac_q0104_b_obs']	& &	///
							& [`eshu_b_ivac_q0508_b_obs']   & [`eshu_n_ivac_q0508_b_obs']	& \\
	
tex \multicolumn{8}{l}{ } \\	
tex $x ~~~Any homelessness services: 	& `home_b_ivac_q0104_b_co' 		& `home_n_ivac_q0104_b_co' 		& `home_r_ivac_q0104_b_pv' & ///
							& `home_b_ivac_q0508_b_co' 		& `home_n_ivac_q0508_b_co' 		& `home_r_ivac_q0508_b_pv' \\	
tex							& `home_b_ivac_q0104_b_se' 		& `home_n_ivac_q0104_b_se' 		& & ///
							& `home_b_ivac_q0508_b_se' 		& `home_n_ivac_q0508_b_se' 		& \\							
tex  				 		& [`home_b_ivac_q0104_b_obs']   & [`home_n_ivac_q0104_b_obs']	& &	///
							& [`home_b_ivac_q0508_b_obs']   & [`home_n_ivac_q0508_b_obs']	& \\
							
tex \bottomrule \\
tex	\end{tabular} }
texdoc close


